<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>echarts地图</title>
    <script src="../js/data.js"></script>
    <script src="../js/vue2.js"></script>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="viewport" id="home">
    <div class="echarts" id="echarts"></div>
</div>
</body>
<script>
    function GetRandomNum(Min, Max) {
        var Range = Max - Min;
        var Rand = Math.random();
        return (Min + Math.round(Rand * Range));
    }

    // 获取数据
    function getData() {
        $.get('../js/data.json', function (data) {
            getEcharts(data)
        });
    }

    // 渲染echarts
    function getEcharts(data) {
        var name = ''
        var chartDom = document.getElementById('echarts');
        var myChart = echarts.init(chartDom);
        var nameMap = '地图数据';
        echarts.registerMap(nameMap, data);
        var mapFeatures = echarts.getMap(nameMap).geoJson.features;
        mapFeatures.forEach(function (v, index) {
            if (index == 0) {
                name = v.properties.name;
            }

        });
        var option = {
            //图例
            geo: {
                map: nameMap,
                zoom: 1,
                label: {
                    normal: {
                        show: false,
                        color: '#000000'
                    },
                    emphasis: {
                        show: false,
                        color: '#292929'
                    }
                },
                roam: false,
                itemStyle: {
                    normal: {
                        areaColor: '#00338F',
                        borderColor: '#0094D6',
                        borderWidth: 0.5,
                        label: {
                            show: false,
                        }
                    },
                    emphasis: {
                        areaColor: '#FFBB07',
                        borderColor: '#0094D6',
                        areaStyle: '#FFBB07',
                        label: {
                            show: false,
                        }
                    }
                },
            },
            series: [
                {
                    map: nameMap,
                    zoom: 1,
                    type: 'map',
                    label: {
                        normal: {
                            show: false,
                            color: '#000000'
                        },
                        emphasis: {
                            show: false,
                            color: '#292929'
                        }
                    },
                    roam: false,
                    itemStyle: {
                        normal: {
                            areaColor: '#00338F',
                            borderColor: '#0094D6',
                            borderWidth: 0.5,
                            label: {
                                show: false,
                            }
                        },
                        emphasis: {
                            areaColor: '#FFBB07',
                            borderColor: '#0094D6',
                            areaStyle: '#FFBB07',
                            label: {
                                show: false,
                            }
                        }
                    },
                }
            ]
        }
        myChart.resize()
        myChart.setOption(option)
        console.log(myChart)
        myChart.dispatchAction({
            type: 'highlight', // 高亮指定的数据图形。通过seriesName或者seriesIndex指定系列。如果要再指定某个数据可以再指定dataIndex或者name。
            seriesIndex: 0,
            name: mapFeatures[2].properties.name
        })
    }

    if (window.location.origin == 'file://') {
        setTimeout(() => {
            getEcharts(gdMap)
        }, 100)
    } else {
        getData()
    }
</script>
</html>
<style>
    html, body {
        padding: 0;
        margin: 0;
    }

    #home {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .echarts {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .info {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;
        color: red;
    }

    .links {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;

    }

    .links a {
        text-decoration: none;
        color: #fff;
    }
</style>
